package com.lhy.skywalking.order.factory;

import com.lhy.skywalking.common.domain.AjaxResult;
import com.lhy.skywalking.order.OrderFeignService;
import feign.FeignException;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class OrderFallbackFactory implements FallbackFactory<OrderFeignService> {
    @Override
    public OrderFeignService create(Throwable throwable) {
        return new OrderFeignService() {
            @Override
            public AjaxResult findById(Long id) {
                if (throwable instanceof FeignException.ServiceUnavailable) {
                    return AjaxResult.error("服务不存在");
                }
                return AjaxResult.error(throwable.getMessage());
            }
        };
    }
}